<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/stylesheets/index.css" />
    <link rel="stylesheet" type="text/css" href="/stylesheets/user.css" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #mask{
            height: 1000px;
            width: 100%;
            background: lightgrey;
            position: absolute;
            opacity: 0.3;
            z-index: 999;
            display: none;
        }
        .edit{
            background: #fff;
            position: absolute;
            z-index: 1000;
            width: 600px;
            left: 50%;
            margin-left: -300px;
            display: none;
        }
        #close{
            background: url("/images/sys_td_btn_3.gif");
            width: 18px;
            height: 18px;
            cursor: pointer;
            float: right;
        }
    </style>
</head>
<body>
<div class="sys_contnt">
    <div class="sys_content_left">
        <ul>
            <li class="sys_content_left_l1"><a href="/department_list" id="groupmanager">机构管理</a></li>
            <li ><a id="useradd" href="/department_add">机构添加</a></li>
        </ul>
    </div>
    <div class="sys_content_right" >
        <div class="sys_user">
            <h1 class="fleft">机构管理</h1>
            <form action="/loging" method="post">
                <input type="submit" class="s_sub" value="搜 索"/>
                <input type="text" class="search" name="search" placeholder="请输入机构名"/>
            </form>
            <table cellpadding="0" border="0" cellspacing="0" class="user clear">
                <tr class="first">
                    <td width="5%"></td>
                    <td width="8%">机构名称</td>
                    <td width="10%">机构编码</td>
                    <td width="5%">描述信息</td>
                    <td width="10%">操作</td>
                </tr>
                <%for(var i = 0; i < departList.length; i++){%>
                <%if(i%2 == 0){%>
                <tr >
                    <td><input type="checkbox" class="checkbox" title="<%= departList[i]["departmentId"]%>" /></td>
                    <td width="5%"><%= departList[i]["departName"]%></td>
                    <td width="5%"><%= departList[i]["departCode"]%></td>
                    <td width="10%"><%= departList[i]["departTip"]%></td>
                    <td>
                        <ul class="user_table_edit w84">
                            <li><input type="button"  class="user_edit"   onclick="editDepart(<%=JSON.stringify(departList[i])%>)"   /></li>
                            <li><input type="button"  class="user_edit"   onclick=""   /></li>
                            <li><input type="button" class="user_del" onclick="deletDep(<%=departList[i]["departmentId"]%>)"></li>
                        </ul>
                    </td>
                </tr>
                <%}else{%>
                <tr class="double">
                    <td><input type="checkbox" class="checkbox" title="<%= departList[i]["departmentId"]%>" /></td>
                    <td width="5%"><%= departList[i]["departName"]%></td>
                    <td width="5%"><%= departList[i]["departCode"]%></td>
                    <td width="10%"><%= departList[i]["departTip"]%></td>
                    <td>
                        <ul class="user_table_edit w84">
                            <li><input type="button"  class="user_edit"   onclick="editDepart(<%=JSON.stringify(departList[i])%>)"   /></li>
                            <li><input type="button"  class="user_edit"   onclick=""   /></li>
                            <li><input type="button" class="user_del" onclick="deletDep(<%=departList[i]["departmentId"]%>)"></li>
                        </ul>
                    </td>
                </tr>
                <%}%>

                <%}%>
                <!--<tr >-->
                    <!--<td><input type="checkbox" class="checkbox" title="" /></td>-->
                    <!--<td width="5%"></td>-->
                    <!--<td width="5%"></td>-->
                    <!--<td width="10%"></td>-->
                    <!--<td>-->
                        <!--<ul class="user_table_edit w84">-->
                            <!--<li><input type="button"  class="user_edit"   onclick=""   /></li>-->
                            <!--<li><input type="button"  class="user_edit"   onclick=""   /></li>-->
                            <!--<li><input type="button" class="user_del" onclick=""></li>-->
                        <!--</ul>-->
                    <!--</td>-->
                <!--</tr>-->
                <!--<tr class="double">-->
                    <!--<td><input type="checkbox" class="checkbox" title=""/></td>-->
                    <!--<td width="5%"></td>-->
                    <!--<td width="5%"></td>-->
                    <!--<td width="10%"></td>-->
                    <!--<td>-->
                        <!--<ul class="user_table_edit w84">-->
                            <!--<li><input type="button"  class="user_edit"   onclick=""   /></li>-->
                            <!--<li><input type="button"  class="user_edit"   onclick=""   /></li>-->
                            <!--<li><input type="button" class="user_del" onclick=""></li>-->
                        <!--</ul>-->
                    <!--</td>-->
                <!--</tr>-->
            </table>
            <div class="div_page2">
                <span class="w5"><input type="checkbox" class="check_all" id="selectall"/></span>
                <span><a href="##" class="btn_del" id="batchdel">删 除</a></span>

                <ul class="change" id="pagelist">
                    <li class="pageChange"><a href="">下一页</a></li>
                    <li class="page"><a href="">1</a></li> 
                    <li class="pageChange"><a href="">上一页</a></li>
                </ul>
            </div>
            <div class="clear"></div>
        </div>
    </div>
</div>
<div id="mask">

</div>
<div class="edit" id="editdepart">
    <div class="user_add">
        <h1>修改机构 <input type="button" id="close" class="user_del"></h1>
        <div class="con">
            <form action="/editdepart" method="post" id="editform">
                <table cellpadding="0" border="0" cellspacing="0" class="d">
                    <tr>
                        <td width="20%" class="td_1">机构名称：</td>
                        <td width="80%"><input type="text" name="departname" id="departname" class="text" value=""/></td>
                    </tr>
                    <tr>
                        <td width="20%" class="td_1">机构编号：</td>
                        <td width="80%"><input type="text" name="departcode" id="departcode" class="text" value=""/></td>
                    </tr>
                    <tr class="tr_5">
                        <td class="td_1"><span class="td_t">备&nbsp;&nbsp;注：</span></td>
                        <td class="texta"><textarea rows="8" cols="34" id="description" name="description"></textarea></td>
                    </tr>
                    <tr>
                        <td>
                            <input type="hidden" name="departmentId" id="departmentId">
                        </td>
                        <td class="td_btn"><input type="submit" class="btn_sub" id="btn" value="提 交"/></td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="/javascripts/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="/javascripts/jQuery.js"></script>
<script type="text/javascript" src="/javascripts/main.js"></script>
<script type="text/javascript" src="/routes/department.js"></script>
<script>
    function editDepart(department) {
        $("#mask").css("display","block");
        window.parent.document.getElementById("mask").style.display="block";
        $("#editdepart").css("display","block");

        $("#departname").val(department["departName"]);
        $("#departcode").val(department["departCode"]);
        $("#description").val(department["departTip"]);
        $("#departmentId").val(department["departmentId"]);
    }
    $("#close").click(function () {
        $("#mask").css("display","none");
        window.parent.document.getElementById("mask").style.display="none";
        $("#editdepart").css("display","none");
    })
    $("#btn").click(function () {
        $("#editform").submit();
        $("#mask").css("display","none");
        window.parent.document.getElementById("mask").style.display="none";
        $("#editdepart").css("display","none");
    });
    function deletDep(departmentId) {
        if (confirm("确认删除该条数据")){
            $.post("/deletedepart",{departmentId:departmentId},function (data) {
                alert(data);
                window.history.go(0);
            })
        } 
    }

    $("#batchdel").click(function () {
        var choose=[];
        $(":checked").each(function () {
            choose.push($(this).attr("title"));
        })
        $.ajax({
            url:"/delet",
            data:{choose:choose.toString()},
            type:"post",
            success:function (data) {
                alert(data);
                window .history.go(0);
            },
            error:function (err) {
                console.log(err);
            }
        })
    })
</script>
</html>